package net.plentz.tagger.data;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import net.plentz.tagger.data.FieldData.Id3v2Field;

public class MusicData {

	public static final Map<Id3v2Field, Field> Id3v2FieldMap = new HashMap<Id3v2Field, Field>();

	public enum Field {

		TITLE(Id3v2Field.TIT2, FieldCategory.PRIMARY, "Title"),
		ARTIST(Id3v2Field.TPE1, FieldCategory.PRIMARY, "Artist"),
		ALBUM(Id3v2Field.TALB, FieldCategory.PRIMARY, "Album"),
		GENRE(Id3v2Field.TCON, FieldCategory.PRIMARY, "Genre"),
		TRACK(Id3v2Field.TRCK, FieldCategory.PRIMARY, "Track"),
		YEAR(new Id3v2Field[] {
				Id3v2Field.TYER, Id3v2Field.TDRC
		}, FieldCategory.PRIMARY, "Year"),

		ALBUMARTIST(Id3v2Field.TPE2, FieldCategory.SECONDARY, "Album Artist"),
		COMMENT(Id3v2Field.COMM, FieldCategory.SECONDARY, "Comment"),
		COMPOSER(Id3v2Field.TCOM, FieldCategory.SECONDARY, "Composer"),
		COPYRIGHT(Id3v2Field.TCOP, FieldCategory.SECONDARY, "Copyright");

		public static final int DEFAULT_SIZE = -1;

		private Id3v2Field[] id3v2fields;
		private FieldCategory category;
		private String label;

		private Field(Id3v2Field id3v2field, FieldCategory category, String label) {
			this(new Id3v2Field[] {
				id3v2field
			}, category, label);
		}

		private Field(Id3v2Field[] id3v2fields, FieldCategory category, String label) {
			this.id3v2fields = id3v2fields;
			this.category = category;
			this.label = label;
			for (Id3v2Field field : id3v2fields) {
				MusicData.Id3v2FieldMap.put(field, this);
			}
		}

		public String getLabel() {
			return this.label;
		}

		public FieldCategory getCategory() {
			return this.category;
		}

		public Id3v2Field[] getId3v2fields() {
			return this.id3v2fields;
		}

	}

	public enum FieldCategory {

		PRIMARY,
		SECONDARY,
		EXTRA

	}

	private String filename;
	private Map<Field, String> fieldValues;
	private ArtworkData artworkData;
	private int samplingRate;
	private float length;

	public MusicData() {
		this.fieldValues = new HashMap<Field, String>();
	}

	public void setFieldValue(Field field, String value) {
		this.fieldValues.put(field, value);
	}

	public String getFieldValue(Field field) {
		return this.fieldValues.get(field);
	}

	public Set<Field> getFields() {
		return this.fieldValues.keySet();
	}

	public ArtworkData getArtworkData() {
		return this.artworkData;
	}

	public void setArtworkData(ArtworkData artwork) {
		this.artworkData = artwork;
	}

	public String getFilename() {
		return this.filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public Map<Field, String> getFieldValues() {
		return this.fieldValues;
	}

	public void setFieldValues(Map<Field, String> fieldValues) {
		this.fieldValues = fieldValues;
	}

	public float getLength() {
		return this.length;
	}

	public void setLength(float length) {
		this.length = length;
	}

	public int getSamplingRate() {
		return this.samplingRate;
	}

	public void setSamplingRate(int samplingRate) {
		this.samplingRate = samplingRate;
	}

}
